<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sale extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();

		$this->load->model('sale_model');
	}

	public function index()
	{
		//get获取查询参数
		$page = intval($this->input->get('page', true)); //页数
		$where['gate'] = $this->input->get('gate', TRUE);
		$where['username'] = $this->input->get('username', TRUE);
		$where['areatype'] = $this->input->get('areatype', TRUE);
		$where['platetype'] = $this->input->get('platetype', TRUE);
		$where['top_urgent'] = $this->input->get('top_urgent', TRUE);
		$where['state'] = $this->input->get('state', TRUE);

		//分页
		$count = $this->sale_model->count_all_list($where); //查询总数
		$config['base_url'] = site_url('admin/sale/index?'); //基本url
		//$config['total_rows'] = $count; //总数据条数
		$config['per_page'] = 10; //每页显示多少条数据
		$this->load->library('pagination', $config);

		//根据条件查询需要显示的数据
		$saleinfos = array();
		if ($count)
		{
			$limit = $config['per_page']; //$this->pagination->per_page;
			$offset = $this->pagination->get_offset($page);
			$saleinfos = $this->sale_model->get_all_list($where, $limit, $offset);
		}

		$this->load->helper('form');
		$data['get'] = $where;
		$data['saleinfos'] = $saleinfos;
		$this->load->view('admin/sale_index', $data);
	}


	/**
	 * 置顶操作
	 */
	public function top()
	{
		$houseid = intval($this->input->get('houseid', true));
		$istop = intval($this->input->get('istop', true));

		$update['houseid'] = $houseid;
		$update['istop'] = $istop;
		$this->sale_model->update($update);

		redirect('admin/sale/index');
	}

	/**
	 * 加急操作
	 */
	public function urgent()
	{
		$houseid = intval($this->input->get('houseid', true));
		$isurgent = intval($this->input->get('isurgent', true));

		$update['houseid'] = $houseid;
		$update['isurgent'] = $isurgent;
		$this->sale_model->update($update);

		redirect('admin/sale/index');
	}

	/**
	 * 删除操作（批量）
	 */
	public function do_dels_ajax()
	{
        $houseids = $this->input->post('houseids', TRUE);
		$houseids == FALSE && show_admin_msg('选择后才允许操作');

		foreach ($houseids as $houseid)
		{
			$this->sale_model->delete($houseid);
		}

        show_admin_msg('操作成功', 'success');
	}
}

/* End of file sale.php */
/* Location: ./application/controllers/admin/sale.php */
